#!/usr/bin env python
###########################################################################
#   Copyright (C) 2008 by Serj Poltavsky                                  #
#   serge.uliss at gmail.com                                              #
#                                                                         #
#   This program is free software; you can redistribute it and/or modify  #
#   it under the terms of the GNU General Public License as published by  #
#   the Free Software Foundation; either version 3 of the License, or     #
#   (at your option) any later version.                                   #
#                                                                         #
#   This program is distributed in the hope that it will be useful,       #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#   GNU General Public License for more details.                          #
#                                                                         #
#   You should have received a copy of the GNU General Public License     #
#   along with this program. If not, see <http://www.gnu.org/licenses/>   #
###########################################################################

class Container(object):
    def __init__(self):
        self.__elements = []

    def __iter__(self):
        return self.__elements.__iter__()

    def append(self, element):
        self.__elements.append(element)

    def at(self, index):
        return self.__elements[index]

    def back(self):
        return self.__elements[-1]

    def clear(self):
        self.__elements = []

    def empty(self):
        return len(self.__elements) == 0

    def exists(self, index):
        try:
            self.__elements[index]
            return True
        except IndexError:
            return False

    def size(self):
        return len(self.__elements)